
package planet.util;

import planet.comun.OracleDBConn;

import java.sql.Blob;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.http.HttpServlet;

public class ServletTraerImagenx{
		  
		  public  byte[] getPhoto(String iNumPhoto)
		       throws Exception, SQLException
		  {

		    String req = "" ;
		    Blob img ;
		    byte[] imgData = null ;
		    // connection con Oracle
		     System.out.println("Dentro del Traer Imagen");
		    
			OracleDBConn cnx = new OracleDBConn();
			Connection conn = cnx.getConnection();
		    conn.setAutoCommit (false);  
		    
		    Statement stmt = conn.createStatement ();
		    
		    // Query
		    req = "Select FOT_USUARIO From USUARIO Where COD_USUARIO = '"+ iNumPhoto.trim() +"'";  
		    
		    ResultSet rset  = stmt.executeQuery ( req ); 
		    
		    while (rset.next ())
		    	
		    	
		    {    
		     System.out.println("esta dentro del while");
		    	img = rset.getBlob(1);
		      imgData = img.getBytes(1,(int)img.length());  		
		    }    
		    
		    rset.close();
		    stmt.close();
		    
		    return imgData ;

		  }
		  
		  public Connection getConnection() {
				OracleDBConn cnx = new OracleDBConn();
				return cnx.getConnection();
			}
		 
		  
		  
		}  